﻿namespace HZY.Shared.Models.PagingViews;

/// <summary>
/// 分页视图模型
/// </summary>
public class PagingView
{
    /// <summary>
    /// 列信息
    /// </summary>
    public List<TableColumnView> Columns { get; set; } = [];

    /// <summary>
    /// 转换后数据
    /// </summary>
    public List<Dictionary<string, object?>> DataSource { get; set; } = [];

    /// <summary>
    /// 总数
    /// </summary>
    public long Total { get; set; }

    /// <summary>
    /// 总页数
    /// </summary>
    public long PageCount { get; set; }

    /// <summary>
    /// 一页显示多少条
    /// </summary>
    public int Size { get; set; }

    /// <summary>
    /// 页码
    /// </summary>
    public int Page { get; set; }

    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="page"></param>
    /// <param name="size"></param>
    public PagingView(int page, int size)
    {
        Page = page;
        Size = size;
    }

    /// <summary>
    /// 创建 PagingView 对象
    /// </summary>
    /// <param name="page"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    public static PagingView Create(int page, int size)
    {
        var pagingView = new PagingView(page, size);
        return pagingView;
    }

    /// <summary>
    /// 仓储主表实体类型
    /// </summary>
    private Type? _mainTableEntityType;

    /// <summary>
    /// 设置主表实体类型
    /// </summary>
    /// <param name="value"></param>
    public void SetMainTableEntityType(Type? value) => _mainTableEntityType = value;

    /// <summary>
    /// 主表实体类型
    /// </summary>
    [JsonIgnore]
    public Type? MainTableEntityType => _mainTableEntityType;
}